﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using TwoWheels.Account;

namespace TwoWheels
{
    public partial class Product : System.Web.UI.Page
    {
        protected String param;
        protected String name;
        protected String inStock;
        protected String price;
        protected String desc;
        protected int productID;

        protected void Page_Load(object sender, EventArgs e)
        {
            String temp = Request["Name"];
            param = "~/ShowImage.aspx?id=" + temp + "&source=Produkt";
            Image1.Src = param;
            name = temp;
            
            const string cnStr = @"Data Source=DUO-P8600;Initial Catalog=TwoWheels;Integrated Security=True";
            TwoWheelsDatabase tdb = new TwoWheelsDatabase(cnStr);

            var pr = from p in tdb.products where p.NazwaProduktu == name select new { p.ProduktowWMagazynie, p.CenaJednostkowa, p.ProduktID };
            inStock = (from n in pr select n.ProduktowWMagazynie).ToList().First().ToString();
            price = (from n in pr select n.CenaJednostkowa).ToList().First().ToString();
            productID = (from n in pr select n.ProduktID).ToList().First();

            desc = "Last year Geoff Kabush rode a Rocky Mountain Vertex Team RSL hardtail to his first World Cup cross-country win. It was ironic, as the Canadian is a long-time proponent of full-suspension race bikes, but at that time Rocky Mountain didn’t have a machine deemed worthy of the task. That’s something that has now been remedied with the new Element RSL, and since it was unveiled at April's Sea Otter Classic Kabush has rarely been seen riding anything else. That suggests Rocky Mountain have built a winner; now he just needs to make it official and win another World Cup or maybe even the World Championships on it. BikeRadar were among the first to receive a production 2011 Element RSL for testing, and we've now put in over a month of trail riding and race miles on the bike. We can report that it's light and laterally stiff, and will certainly make you happy if you have World Cup aspirations. However, if your ambitions stretch beyond the racetrack, its performance is stymied by poor shifting performance, a low bottom bracket that could catch you off guard, and suspension bob when standing or sprinting. ";

            if (Session["UserShoppingCartInfo"] != null) AddButton.Visible = true;
        }

        protected void addToCart_Button(object sender, EventArgs e)
        {
            UserShoppingCart cart = Session["UserShoppingCartInfo"] as UserShoppingCart;
            int id = productID;

            cart.addToCart(id);

            Response.Redirect("~/Account/Cart.aspx");
        }
    }

 
}